package com.miniapp.web.controller.miniapp;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.miniapp.common.annotation.Log;
import com.miniapp.common.core.controller.BaseController;
import com.miniapp.common.core.domain.AjaxResult;
import com.miniapp.common.enums.BusinessType;
import com.miniapp.common.core.domain.entity.miniapp.MiniApp;
import com.miniapp.basics.service.IMiniAppService;
import com.miniapp.common.utils.poi.ExcelUtil;
import com.miniapp.common.core.page.TableDataInfo;

/**
 * 小程序信息Controller
 * 
 * @author 盖子
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/basics/miniapp")
public class MiniAppController extends BaseController
{
    @Autowired
    private IMiniAppService miniAppService;

    /**
     * 查询小程序信息列表
     */
    @PreAuthorize("@ss.hasPermi('basics:miniapp:list')")
    @GetMapping("/list")
    public TableDataInfo list(MiniApp miniApp)
    {
        startPage();
        List<MiniApp> list = miniAppService.selectMiniAppList(miniApp);
        return getDataTable(list);
    }

    /**
     * 导出小程序信息列表
     */
    @PreAuthorize("@ss.hasPermi('basics:miniapp:export')")
    @Log(title = "小程序信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MiniApp miniApp)
    {
        List<MiniApp> list = miniAppService.selectMiniAppList(miniApp);
        ExcelUtil<MiniApp> util = new ExcelUtil<MiniApp>(MiniApp.class);
        util.exportExcel(response, list, "小程序信息数据");
    }

    /**
     * 获取小程序信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('basics:miniapp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(miniAppService.selectMiniAppById(id));
    }

    /**
     * 新增小程序信息
     */
    @PreAuthorize("@ss.hasPermi('basics:miniapp:add')")
    @Log(title = "小程序信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MiniApp miniApp)
    {
        return toAjax(miniAppService.insertMiniApp(miniApp));
    }

    /**
     * 修改小程序信息
     */
    @PreAuthorize("@ss.hasPermi('basics:miniapp:edit')")
    @Log(title = "小程序信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MiniApp miniApp)
    {
        return toAjax(miniAppService.updateMiniApp(miniApp));
    }

    /**
     * 删除小程序信息
     */
    @PreAuthorize("@ss.hasPermi('basics:miniapp:remove')")
    @Log(title = "小程序信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(miniAppService.deleteMiniAppByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('basics:miniapp:list')")
    @GetMapping("/listSelect")
    public AjaxResult listSelect()
    {
        JSONArray data = miniAppService.listSelect();
        return success(data);
    }
}
